package com.education.business.service.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.business.mapper.education.StudentInfoMapper;
import com.education.business.mapper.system.ExamRoomMapper;
import com.education.business.mapper.system.ExamRoomStudentMapper;
import com.education.business.service.BaseService;
import com.education.common.model.PageInfo;
import com.education.model.dto.ExamRoomStudentDto;
import com.education.model.entity.ExamRoomStudent;
import com.education.model.entity.StudentInfo;
import com.education.model.entity.TestPaperInfo;
import com.education.model.request.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamRoomStudentService extends BaseService<ExamRoomStudentMapper, ExamRoomStudent> {
    @Autowired
    private ExamRoomStudentMapper examRoomStudentMapper;
    private StudentInfoMapper studentInfoMapper;
    /**
     * 按考场统计学生人数
     * @param examRoomId
     * @return
     */
    public Integer getExamRoomStudentCount(Integer examRoomId){
        LambdaQueryWrapper<ExamRoomStudent> queryWrapper = Wrappers.<ExamRoomStudent>lambdaQuery().eq(ExamRoomStudent::getExamRoomId,examRoomId);
        return  examRoomStudentMapper.selectCount(queryWrapper);
    }



    /**
     * 按考场统计学生人数
     * @param
     * @return
     */

    public PageInfo<ExamRoomStudentDto> selectPageList(PageParam pageParam, ExamRoomStudent examRoomStudent) {
        Page<ExamRoomStudentDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.selectPageList(page, examRoomStudent));
    }

    /**
     * 循环遍历批量增加
     * @param ids
     */
    public  void addExamRoomStudent(List<Integer> ids){

        for(Integer id:ids){
            StudentInfo studentInfo = studentInfoMapper.selectById(id);
            ExamRoomStudent examRoomStudent = new ExamRoomStudent();
            examRoomStudent.setStudentInfoId(studentInfo.getId());
            baseMapper.insert(examRoomStudent);

        }
    }

    /**
     * 根据id实现批量删除
     *
     * @param
     * @param maps
     * @return
     */
    public int deleteStudentAllById(List maps) {
//          examRoomStudentMapper.deleteBatchIds(maps);
        return examRoomStudentMapper.deleteBatchIds(maps);
    }
}
